/**
 * Notes: 门禁访问日志实体 - 宠物门店预约小程序
 * Date: 2025-01-27 
 */

const BaseModel = require('./base_model.js');
class AccessLogModel extends BaseModel {}

// 集合名
AccessLogModel.CL = "ax_access_logs";

AccessLogModel.DB_STRUCTURE = {
	_pid: 'string|true',
	_id: 'string|true|comment=访问日志唯一ID',
	userId: 'string|true|comment=用户ID',
	storeId: 'string|true|comment=门店ID',
	appointmentId: 'string|false|comment=关联的预约单ID',
	
	doorLockId: 'string|true|comment=门锁设备ID',
	action: 'string|true|comment=操作类型',
	status: 'string|true|comment=访问状态',
	
	// 冗余字段，便于查询和统计
	userName: 'string|false|comment=用户昵称',
	storeName: 'string|false|comment=门店名称',
	appointmentNumber: 'string|false|comment=预约单号',
	
	accessTime: 'int|true|comment=访问时间',
	responseTime: 'int|false|comment=响应时间',
	errorMessage: 'string|false|comment=错误信息',
	
	createTime: 'int|true|comment=创建时间',
}

// 字段前缀
AccessLogModel.FIELD_PREFIX = "";

/**
 * 访问操作类型
 */
AccessLogModel.ACTION = {
	OPEN_DOOR: 'open_door',         // 开门
	SCAN_QR: 'scan_qr',             // 扫码
	CHECK_IN: 'check_in',           // 签到
	CHECK_OUT: 'check_out'          // 签退
};

AccessLogModel.ACTION_DESC = {
	OPEN_DOOR: '开门',
	SCAN_QR: '扫码',
	CHECK_IN: '签到',
	CHECK_OUT: '签退'
};

/**
 * 访问状态
 */
AccessLogModel.STATUS = {
	SUCCESS: 'success',             // 成功
	FAILED: 'failed',               // 失败
	DENIED: 'denied',               // 拒绝访问
	TIMEOUT: 'timeout'              // 超时
};

AccessLogModel.STATUS_DESC = {
	SUCCESS: '成功',
	FAILED: '失败',
	DENIED: '拒绝访问',
	TIMEOUT: '超时'
};

module.exports = AccessLogModel;